package com.bianmaba.controllers.datacollection;

import com.bianmaba.beans.datacollection.TaskInstance;
import com.bianmaba.commons.bean.result.QueryResult;
import com.bianmaba.commons.data.jpa.domain.request.PageableRequest;
import com.bianmaba.controllers.base.support.CrudControllerSwaggerSupport;
import com.bianmaba.services.datacollection.ITaskInstanceService;
import com.bianmaba.spring.mvc.annotation.RequestResponseBodyConfig;
import com.bianmaba.spring.mvc.config.annotation.EntityParam;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;

@Api(description = "任务实例API(运行中、已完成)")
@RestController
@RequestMapping(value = "datacollection/task_instance")
public class TaskInstanceController extends CrudControllerSwaggerSupport<TaskInstance, String> {
    @Autowired
    private ITaskInstanceService service;

    protected ITaskInstanceService getService() {
        return service;
    }

    @RequestMapping("query_done")
    @RequestResponseBodyConfig
    public QueryResult<List<TaskInstance>> queryDone(@EntityParam LinkedHashMap<String, Object> params, @EntityParam PageableRequest pageable) {
        params.put("status_notin", new Integer[]{1, 2});
        return super.query(params, pageable);
    }

    @RequestMapping("query_running")
    @RequestResponseBodyConfig
    public QueryResult<List<TaskInstance>> queryRunning(@EntityParam LinkedHashMap<String, Object> params, @EntityParam PageableRequest pageable) {
        params.put("status_in", new Integer[]{1, 2});
        return super.query(params, pageable);
    }
}
